package com.javafamily.familydemo.service;

import com.javafamily.familydemo.dao.PetsDAO;
import com.javafamily.familydemo.model.Pets;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PetsServiceImpl implements PetsService {

    @Resource
    private PetsDAO petsDAO;
    @Resource
    private JdbcTemplate familyJdbcTemplate;
    @Resource
    private JdbcTemplate family2JdbcTemplate;


    @Override
    public void savePets(Pets pets) {
        petsDAO.save(pets, familyJdbcTemplate);
        petsDAO.save(pets, family2JdbcTemplate);
    }

    @Override
    public void deletePets(long id) {
        petsDAO.deleteById(id, null);
    }

    @Override
    public void updatePets(Pets pets) {
        petsDAO.updateById(pets, null);
    }

    @Override
    public Pets getPets(Long id) {
        return petsDAO.searchById(id, familyJdbcTemplate);
    }

    @Override
    public List<Pets> getAll() {
        return petsDAO.findAll(familyJdbcTemplate);
    }
}
